﻿/* 
 *  <copyright file="PlatformerScreen.cs" company="Wesley Jowitt">
 *  
 *  SobrietyEngine: Copyright (c) 2011 Wesley Jowitt
 *  
 *  This software is distributed under a software license.
 *   * As of the creation time of this file, the license in use is the Microsoft Permissive License (Ms-PL) 
 *    * The license can be viewed at:
 *     * License.Txt in the root folder of this project
 *      * http://sobrietyengine.codeplex.com/license
 *       * http://www.microsoft.com/opensource/licenses.mspx
 *       
 *  </copyright>
 *   */

using System;
using Microsoft.Xna.Framework;
using SEGameExample.Kludge;
using SobrietyEngine.Actor;
using SobrietyEngine.Components;
using SobrietyEngine.Components.Common;
using SobrietyEngine.Components.Graphic;
using SobrietyEngine.Components.Common;
using SobrietyEngine.Logging;
using SobrietyEngine.Scene;
using SobrietyEngine.Screens;
using SEGameExample.InputMappers;

namespace SEGameExample.Screens
{
    class XModelAnim: BaseLevel 
    {
        public XModelAnim()
            : base("XModelAnimScene")
        {
        }

        public override void Initialize()
        {
            base.Initialize();

            //set up our PlayerOne (first found user with an Xbox 360 controller)
            //turn off any controllers that may be active (shoudl always disable controllers when you are finished!)
            PlayerOne.DisableAllInputMappers();
            if (!PlayerOne.HasInputMapper(typeof(PlatformerEventMapper)))
                PlayerOne.AddInputMapper(new PlatformerEventMapper(EventRouter, PlayerOne.Guid));
            PlayerOne.EnableInputMapper(typeof(PlatformerEventMapper));

            //turn on logging of some events
            EventRouter.LogRaisedEvents = true;
            EventRouter.LogEventIgnore.Add("Input.");
            EventRouter.LogEventIgnore.Add(".Move");
            EventRouter.LogEventIgnore.Add(".Rotate");
            EventRouter.LogEventIgnore.Add(".ActorInit");

            //set some logging options
            Logger.AppendLoggingType(Logger.LogType.AssertOnError |
                                     Logger.LogType.VSConsole |
                                     Logger.LogType.RaiseLogEvent );

            //forward declaration of some variables used in here
            IActor actor = null;
            IScene scene = SceneGameService.Scenes[SceneName];

            //test loading UDMF formatted actor tempaltes
            //String actorData = assetGameService.Load<String>("actors/actorDefs");
            //ActorDefinitionReader.Load(actorData);
            actorGameService.LoadActorTemplates("actors/actorDefs");

   
            //lets manually create an actor with an animation component
            actor = scene.CreateEmptyActor();
            actor.AttachComponent(new PositionCmp(new Vector3(0,0,-5)));
            actor.AttachComponent(new ScaleCmp( new Vector3(0.2f,0.2f,0.2f)));
            AnimatedMeshCmp amcSoldier = new AnimatedMeshCmp("animTest/marine", "animTest/skinFX");
            actor.AttachComponent(amcSoldier);
            actor.Initialize();
            amcSoldier.SetAnimation("idle");


            actor = scene.CreateEmptyActor();
            actor.AttachComponent(new PositionCmp(new Vector3(5, 0, -10)));
            AnimatedMeshCmp amc = new AnimatedMeshCmp("animTest/dwarfmodel", "animTest/skinFX");
            actor.AttachComponent(amc);
            actor.Initialize();
            amc.SetAnimation("idle0");
            //lets try another
            
            /*
            actor = scene.CreateEmptyActor();
            actor.AttachComponent(new PositionCmp(new Vector3(0, 0, 0)));
            actor.AttachComponent(new ScaleCmp(new Vector3(0.1f,0.1f,0.1f)));
            IOrientation o = new OrientationCmp();
            o.WorldAxisPitch((float)(Math.PI/2));
            o.WorldAxisRoll((float)(Math.PI));
            o.WorldAxisYaw((float)(Math.PI));
            actor.AttachComponent((IComponent)o);
            //actor.AttachComponent(new AnimatedMeshCmp("animTest/soldier_Walk/walk-w-gun", "animTest/skinFX"));
            actor.AttachComponent(new ModelCmp("Models/Lance"));
            actor.Initialize();
            */

            //Test some gui and hud stuff
            //create a 2D gui camera     
            //IActor cam2D = GUISpawner.Camera2D(Scene, ScreenManager.FullScreenViewport);
            IActor cam2d = SobrietyEngine.Actor.Builders.Cameras.GuiCameraBldr.Build(Scene, ScreenManager.FullScreenViewport);

            //some help text about controls
            String help = "UDMF from DoomBuilder. \n ";
            help += "Left thumbstick moves\n";
            help += "(A) jumps, (RB) super jumps, \n";
            help += "(B) exits, (Y) toggles physics debug \n";
            help += "(LB) toggle debug console\n";

            SobrietyEngine.Actor.Builders.GUI.Text2D.Build(Scene, new Vector2(0, ScreenManager.FullScreenViewport.Height / 2), help);

            actor = SobrietyEngine.Actor.Builders.Cameras.FreeFlyCameraBldr.Build(scene, ScreenManager.FullScreenViewport, ScreenManager.GraphicsDevice, PlayerOne.Guid);

            //turn on our controllers
            SceneGameService.Scenes[SceneName].EnableControllers();
        }

    }
}